package schoolWork;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class BookInfoApp extends JFrame {
    private JComboBox<String> bookComboBox;
    private JTextArea bookInfoTextArea;

    public BookInfoApp() {
        setTitle("Book Information");
        setSize(400, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        bookComboBox = new JComboBox<>(new String[]{"Book1", "Book2", "Book3", "Book4", "Book5", "Book6"});
        bookInfoTextArea = new JTextArea();

        bookComboBox.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String selectedBook = (String) bookComboBox.getSelectedItem();
                displayBookInfo(selectedBook);
            }
        });

        add(bookComboBox, BorderLayout.NORTH);
        add(bookInfoTextArea, BorderLayout.CENTER);
    }

    private void displayBookInfo(String book) {
        // Here you can add logic to fetch book information from a database or API
        // For now, we will just display some dummy information
        String info = "Book: " + book + "\nPrice: $10\nPublisher: ABC Publishing";
        bookInfoTextArea.setText(info);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                BookInfoApp app = new BookInfoApp();
                app.setVisible(true);
            }
        });
    }
}
